package mylist;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);
        //list.add(0,99);
        List<Integer> list1 = list.subList(1,3);
        // subList此处的截取并不会产生新的对象
        System.out.println(list1);
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();
        System.out.println(list);
        for (Integer x: list) {
            System.out.print(x+" ");

        }
        System.out.println();
        /**
         * 迭代器 遍历 集合类
         */
        System.out.println("===== 迭代器 =====");
        Iterator<Integer> it = list.iterator();
        while(it.hasNext()){
            System.out.print(it.next()+" ");
        }
        System.out.println();
        ArrayList<Integer> list2 = new ArrayList<>(15);
    }
    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.display();
        System.out.println(myArrayList.contains(1));
        System.out.println(myArrayList.contains(3));
        System.out.println(myArrayList.contains(9));
        myArrayList.set(2,999);
        myArrayList.display();

    }
}
